

#include <sys/cdefs.h>

#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <assert.h>
#include <string.h>
#else
#include <lib/libkern/libkern.h>
#endif

__strong_alias(rindex, strrchr)
char *
strrchr(const char *p, int ch)
{
	char *save;
	const char c = ch;

	_DIAGASSERT(p != NULL);

	for (save = NULL;; ++p) {
		if (*p == c) {
			/* LINTED const cast-away */
			save = __UNCONST(p);
		}
		if (!*p)
			return(save);
	}
	/* NOTREACHED */
}
